package flc.ast.dialog;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.SpanUtils;

import flc.ast.R;
import flc.ast.databinding.DialogCreateShortcutBinding;
import stark.common.basic.base.BaseNoModelDialog;


/**
 * Author：daizhongbin on 2021/8/23
 * Email：1027154338@qq.com
 * Desc:
 */
public class ShortcutCreateDialog extends BaseNoModelDialog<DialogCreateShortcutBinding> {

    private Activity mActivity;
    public Bitmap mBitmap;
    public String mName;


    public ShortcutCreateDialog(@NonNull Activity activity) {
        super(activity);
        mActivity = activity;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_create_shortcut;
    }

    @Override
    protected void initView(View view) {
        configTip();
        if (mBitmap!=null){
            mDataBinding.ivImg.setImageBitmap(mBitmap);
            mDataBinding.etName.setText(mName);
            mDataBinding.ivImg.setVisibility(View.VISIBLE);
            mDataBinding.etName.setVisibility(View.VISIBLE);
        }else {
            mDataBinding.ivImg.setVisibility(View.GONE);
            mDataBinding.etName.setVisibility(View.GONE);
        }
        mDataBinding.btnCancel.setOnClickListener(v -> {
            dismiss();
        });
        mDataBinding.btnCreate.setOnClickListener(v -> {
            dismiss();
            if (listener != null){
                listener.clickConfirm();
            }
        });
    }


    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm();
    }



    private void configTip() {
        SpanUtils.with(mDataBinding.tvTip)
                .append("提示：若无法创建，请先点击去")
                .append("获取桌面快捷方式权限")
                .setClickSpan(Color.parseColor("#FF0000"), true, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AppUtils.launchAppDetailsSettings();
                    }
                })
                .create();
    }

}
